<!DOCTYPE html>
<html lang="en" style="height:100%;">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <style type="text/css">
        td {
            padding: 2px 0px;
            text-align: left;
            border: 1px solid #999;
        }
    </style>
    <link href="/resources/gentelella/css/custom.min.css" rel="stylesheet">
    <link href="/resources/css/table.css?r=3" rel="stylesheet">
    <link href="/resources/css/fk.css?r=3" rel="stylesheet">
    <link href="/resources/css/fk_2.css?r=3" rel="stylesheet">
    <script src="/resources/js/jquery-1.11.1.min.js"></script>
    <script src="/resources/js/self.js"></script>
    <script type="text/javascript" src="/resources/js/md5.js"></script>
    <script type="text/javascript" src="/resources/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="/resources/js/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/resources/js/Util.js"></script>
    <script src="/resources/js/fk.js"></script>
</head>
<body style="background-color: #fff !important;">

<div class="table-container">
    <div style="font-size: 30px;width:78%;margin: auto">
        <div style="float: left">
            <img src="/resources/images/jdbz.png" style="height: 40px;width: 40px"/>
        </div>
        <div style="float: left">
            <span style="padding-left: 5px">禁毒清源系统</span>
        </div>
        <div style="clear:both"></div>

    </div>
    <div class="zctitle">
        企业信息
    </div>
    <table>
        <tr>
            <td class="name" >
                名称：
            </td>
            <td>
                <input type="text" name="name"   id="name"
                       class="form-control form-data ">
                <input type="hidden" name="id" class="form-data">
            </td>
            <td class="name">
                行业：
            </td>
            <td>
                <input type="text" name="business" id="business"
                       class="form-control form-data ">
            </td>
            <td class="name">
                企业所在地：
            </td>
            <td>
                <input type="text" name="companyAddress" id="companyAddress"
                       class="form-control form-data ">
            </td>
            <td class="name">
                建立时间：
            </td>
            <td>
                <input type="text" name="startTime" id="startTime"
                       class="form-control form-data " onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})">
            </td>
        </tr>
        <tr>
            <td class="name" >
                法人：
            </td>
            <td>
                <input type="text" name="chargePeople" id="chargePeople"
                       class="form-control form-data ">
            </td>
            <td class="name">
                性别：
            </td>
            <td>
                <select name="sex" class="form-control form-data col-md-7 col-xs-12">
                    <option value="男">男</option>
                    <option value="女">女</option>
                    <option value="保密">保密</option>
                </select>
            </td>
            <td class="name">
                身份证号：
            </td>
            <td>
                <input type="text" id="idCard" name="idCard"
                       class="form-control form-data ">
            </td>
            <td class="name">
                联系方式：
            </td>
            <td>
                <input type="text" id="telephone" name="telephone"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name" >
                法人地址：
            </td>
            <td colspan="3">
                <input type="text" id="personAddress" name="personAddress"
                       class="form-control form-data ">
            </td>
            <td class="name">
                企业状态：
            </td>
            <td colspan="3">
                <input style="width:15px;height:15px" type="radio" name="status" class="form-data"
                       value="inProduction"/>
                <span>正常</span>
                <!--<input style="width:15px;height:15px" type="radio" name="status" class="form-data"-->
                       <!--value="discontinued"/>-->
                <!--<span>停产</span>-->
                <input style="width:15px;height:15px" type="radio" name="status" class="form-data"
                       value="suspend"/>
                <span>锁定</span>
                <input style="width:15px;height:15px" type="radio" name="status" class="form-data"
                       value="closed"/>
                <span>注销</span>
            </td>
        </tr>
        <tr>
            <td class="name" >
                经理：
            </td>
            <td>
                <input type="text" name="manager" id="manager"
                       class="form-control form-data ">
            </td>
            <td class="name">
                性别：
            </td>
            <td>
                <select name="managerSex" class="form-control form-data col-md-7 col-xs-12">
                    <option value="男">男</option>
                    <option value="女">女</option>
                    <option value="保密">保密</option>
                </select>
            </td>
            <td class="name">
                身份证号：
            </td>
            <td>
                <input type="text" id="managerIdCard" name="managerIdCard"
                       class="form-control form-data ">
            </td>
            <td class="name">
                经理电话：
            </td>
            <td>
                <input type="text" id="managerTel" name="managerTel"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name" >
                经理地址：
            </td>
            <td colspan="7">
                <input type="text" id="managerAddress" name="managerAddress"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name" >
                企业简介：
            </td>
            <td colspan="7">
                <textarea class="form-control form-data" name="desc" rows="3" placeholder=""></textarea>
            </td>
        </tr>
        <tr>
            <td class="name" colspan="3">
                法人照片
                <button onclick="$('#fileUploadLegalPersonPhotos').click()" class="btn btn-success">上传文件
                </button>
                <input type="file" name="file" multiple="true" accept="image/*"
                       id="fileUploadLegalPersonPhotos" style="display:none"
                       onchange="uploadFile('fileUploadLegalPersonPhotos','legalPersonPhotos', 'imgDiv2', 100, 100,'image')"/>
            </td>
            <td class="name" colspan="3">
                实景图片
                <button id="uploadBtn" onclick="$('#fileUpload').click()" class="btn btn-success">上传文件
                </button>
                <input type="file" name="file" multiple="true" accept="image/*" id="fileUpload"
                       style="display:none"
                       onchange="uploadFile('fileUpload','image', 'imgDiv', 100, 100,'image')"/>

            </td>
            <td class="name" colspan="3">
                制度汇编
                <button class="btn btn-success" onclick="$('#file_input').click();">
                    上传文件
                </button>

                <input type="file" id="file_input" name="file" onchange="uploadFileId('file')"
                       value="Upload your resume"
                       style="opacity: 0;width: 0px;display: none">

            </td>
        </tr>
        <tr>

            <td colspan="3" style="text-align: center">
                <div id="imgDiv2" style="padding-top: 23px">
                    <img src="" style="cursor: pointer; width:100px;height: 100px"
                         onclick="deleteImage(event,this)" title=""/>
                </div>
            </td>
            <td colspan="3" style="text-align: center">
                <div id="imgDiv" style="padding-top: 23px">
                    <img src="" style="cursor: pointer; width:100px;height: 100px"
                         onclick="deleteImage(event,this)" title=""/>
                </div>
            </td>
            <td colspan="3" style="text-align: center">
                <div id="file_div" style="margin-top: 20px;">
                </div>
            </td>
        </tr>

        <!--<tr>-->
            <!--<td colspan="4" style="text-align: center">-->
                <!--<div id="imgDiv3" style="padding-top: 23px">-->
                    <!--<img src="" style="cursor: pointer; width:100px;height: 100px"-->
                         <!--onclick="deleteImage(event,this)" title=""/>-->
                <!--</div>-->
            <!--</td>-->
            <!--<td colspan="4" style="text-align: center">-->
                <!--<div id="imgDiv4" style="padding-top: 23px">-->
                    <!--<img src="" style="cursor: pointer; width:100px;height: 100px"-->
                         <!--onclick="deleteImage(event,this)" title=""/>-->
                <!--</div>-->
            <!--</td>-->
        <!--</tr>-->
        <tr>
            <td colspan="9">
                <button onclick="save()" class="btn btn-success">下一步</button>
            </td>


        </tr>

    </table>
</div>



</body>
<script type="text/javascript">
    $(function () {
        initData();
    });

    function initData() {
        $.ajax({
            url: "/trans/company/find.do",
            type: 'post',
            dataType: 'json',
            success: function (data) {
                console.log(data);
                if (data.success) {
                    initPageDate(data.data, '.form-data');
                    $("#imgDiv img").attr("src", data.data.image);
                    $("#imgDiv2 img").attr("src", data.data.legalPersonPhotos);
                    $("#imgDiv3 img").attr("src", data.data.processImage);
                    $("#imgDiv4 img").attr("src", data.data.equationImage);
                    addFileInfoToTable(data.data.fileInfoList, 'file');
                }
            }
        });
        $("#account").attr('readonly', 'readonly');
    }

    function save() {
        var params = getPageDataByClass("form-data");
        var flag = false;
        $(".form-data").each(function (index,e) {
            var elementName  = $(e).attr("name");
            var tagName = $(e).prop("tagName");
            if(tagName =='INPUT' || tagName =='SELECT' || tagName =='TEXTAREA'){
                if(strIsNull(params[elementName])) {
                    flag = true;
                }
            }
        });
        if(flag){
            alert("还没有没填写的项目，请填写完整");
            return;
        }
        // if (strIsNull(params['name'])) {
        //     alert("请输入企业名称");
        //     return;
        // }
        // if (strIsNull(params['business'])) {
        //     alert("请输入企业所属行业");
        //     return;
        // }
        // if (strIsNull(params['status'])) {
        //     alert("请选择企业状态");
        //     return;
        // }
        var img = $("#imgDiv img");
        if (img.length > 0) {
            params['image'] = $(img[0]).attr("src");
        } else {
            alert("请上传实景照片");
            return;
        }
        params.regulation = "";
        $("input[name='file_id']").each(function (index, files) {
            if (files == "") {
                params.regulation = $(this).val();
            } else {
                params.regulation = params.regulation + "," + $(this).val();
            }
        });
        params['legalPersonPhotos'] = getImagePath("legalPersonPhotos");
        params['equationImage'] = getImagePath("equationImage");
        params['processImage'] = getImagePath("processImage");
        $.ajax({
            url: "/trans/company/save.do",
            data: params,
            dataType: 'json',
            type: 'post',
            success: function (data) {
                console.log(data);
                if (data.success) {
                    alert("保存成功");
                    window.location.href = "/html/trans/zhuce_2.html";
                } else {
                    alert(data.msg);
                }
            }
        });
    }
    function downLoadFile() {
        var url = $("input[name='regulation']").val();
        window.open(url, "_blank");
    }
    function uploadFileId(fileType) {
        $.ajaxFileUpload({
            url: "/file/uploadFile.do?_t=" + new Date().getTime(),            //需要链接到服务器地址
            secureuri: false,//是否启用安全提交，默认为false
            fileElementId: fileType + '_input',                        //文件选择框的id属性
            dataType: 'text',                                     //服务器返回的格式，可以是json, xml
            success: function (data, status) {//服务器成功响应处理函数
                var rpeObj = $.parseJSON(data);
                var fileInfoList = rpeObj.data;
                addFileInfoToTable(fileInfoList, fileType);

            }
        });
    }
    function addFileInfoToTable(fileInfoList, fileType) {
        $(fileInfoList).each(function (index, file) {
            var fileHtml = "<div  style='border-radius: 2px; width:100%;height:100px;float: left; border: 2px #ffffff solid;'>" +

                "<div align='center' style='height:80px;margin-bottom: 0px;'>" +
                "<div align='center' onclick='downLoadFile(\"" + file.path + "\",\"" + file.name + "\")' ><input type='hidden' name='" + fileType + "_id' value='" + file.id + "'>" + file.name + "</div>" +

                "<button  style='margin-left: 20px;' " +
                "onclick='downLoadFileId(\"" + file.path + "\",\"" + file.name + "\")' " +
                "name='download' extendData='" + file.id + "'class='btn btn-primary'>下载</button>" +
                "<button  style='margin-left: 20px;' name='delete' extendData='" + file.id + "'class='btn btn-primary'>删除</button><div>"
            "</div>";
            $("#" + fileType + "_div").html(fileHtml);

        });
        $("button[name='delete']").unbind('click');
        $("button[name='delete']").click(function () {
            var id = $(this).attr("extendData");
            $.ajax({
                type: "POST",
                url: "/file/delete.do?_t=" + new Date().getTime(),
                data: "fileId=" + id,

                success: function (result) {
                    alert("删除成功");
                },

                error: function (XMLHttpRequest, textStatus, thrownError) {
                    /* alert("系统异常");*/
                }
            });
            $(this).parent().parent().remove();
        });
    }


</script>
</html>